/*
 * graph2D
 * Copyright (c) 2009 Shun Moriya <shun@mnu.sakura.ne.jp>
 *
 * The MIT License
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
 * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR
 * THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 */

#if !defined(___GRAPH2D_AUDIO_PLAYER_H___)
#define ___GRAPH2D_AUDIO_PLAYER_H___

#include "common.h"
#include "abort.h"
#include <string>

namespace Graph2D
{
	class AudioPlayer
	{
#if defined(TARGET_IPHONE)
		static const int AUDIO_PLAYER_MAX_TRACK = 2;
#else
		static const int AUDIO_PLAYER_MAX_TRACK = 3;
#endif

	public:
		static AudioPlayer& getInstance();

		int talk(const std::string& filename);
		int play(const std::string& filename, const float value, const float second);
		void pause(const int track, const bool on, const float second);
		void stop(const int track, const float second);
		void volume(const int track, const float value, const float second);

		const std::string& getFilename(const int track) const;

		bool isPlaying(const int track) const;

		double getCurrentTime(const int track) const;
		void setCurrentTime(const int track, const double second);

		void onUpdate(const float deltaTime);

	private:
		typedef struct Environment
		{
			std::string filename;
			void* player;
			float deltaVolume;				//!< フェード差分
			float targetVolume;				//!< フェード目的色
			float timeVolume;				//!< フェード時間
			unsigned char flag;
			unsigned char pad[3];
		}Environment;

		AudioPlayer();
		~AudioPlayer();
		Environment* find(const std::string filename);

		Environment tracks[AUDIO_PLAYER_MAX_TRACK];
	};
}

#endif
